@extends('Backstage.Layouts.layout')

@section('content')

    <div class="site-text site-block">
        <form class="layui-form layui-form-pane" action="">
            <input id="admin_user_id" name="id" type="hidden" value="{{$data->admin_user_id}}">
            {{csrf_field()}}
            <div class="layui-form-item">
                <label class="layui-form-label">账号邮箱</label>
                <div class="layui-input-block">
                    <input value="{{$data->admin_user_mail}}" type="text" name="param[admin_user_mail]" lay-verify="email" lay-vertype="tips"  autocomplete="off" placeholder="请输入邮箱" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账号名称</label>
                <div class="layui-input-block">
                    <input value="{{$data->admin_user_name}}" type="text" name="param[admin_user_name]" lay-verify="required" lay-vertype="tips"  autocomplete="off" placeholder="请输入名称" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码设置</label>
                <div class="layui-input-inline">
                    <input type="password" name="param[admin_user_password]"   placeholder="请输入密码" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux">(密码修改,此处留空则不修改)</div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">头像</label>
                <div class="layui-input-inline">
                    <input id="admin_user_headimg" value="{{$data->admin_user_headimg}}" type="text" name="param[admin_user_headimg]" lay-verify="url" lay-vertype="tips"  autocomplete="off" placeholder="请输入头像网址" class="layui-input">
                </div>
                <div class="layui-input-inline">
                    <button type="button" class="layui-btn" id="upload-img">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                </div>
                <div class="layui-input-inline">
                    <img style="width: 80px;height: 80px" id="headimg" src="{{$data->admin_user_headimg}}">
                </div>

            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="form">立即提交</button>
                </div>
            </div>
        </form>
    </div>

@stop

@section('script')

<script>
    layui.use(['upload','form'], function(){
        var upload = layui.upload;
        //执行实例
        var uploadInst = upload.render({
            elem: '#upload-img' //绑定元素
            ,url: '{{URL::route('admin_upload_img')}}' //上传接口
            ,data:{_token:'{{csrf_token()}}'}
            ,done: function(res){
                //上传完毕回调
                $('#admin_user_headimg').val(res.data.src);
                $('#headimg').attr('src',res.data.src);
                layer.msg('上传成功');
            }
            ,error: function(){
                //请求异常回调
                layer.msg('上传失败');
            }
        });

        var form = layui.form;
        //监听提交
        form.on('submit(form)', function(data){

            var $this = $(data.elem);
            $this.attr('disabled', 'disabled');
            layer.msg('数据请求中···', {
                icon: 16
                ,shade: 0.01
            },0);
            $.ajax({
                url: '{{URL::route('admin_index_upuserdata')}}',
                data: data.field,
                type: 'post',
                cache: false,
                dataType: 'json',
                success: function (data) {
                    layer.closeAll();
                    if (data['status'] == 1) {

                        layer.msg(data['msg'], { icon: 1});
                        location.replace(location.href);

                    } else {
                        layer.msg(data['msg'], { icon: 2});
                        $this.attr("disabled",false);
                    }
                },
                error: function () {
                    layer.closeAll();
                    layer.msg('请求发生错误');
                    $this.attr("disabled",false);
                }
            });

            return false;

        });
    });



</script>
@stop